package com.sangmo.fts.process.receivable.repo;

import com.sangmo.boot.framework.plugin.dataview.spi.jpa.IJpaDataViewRepo;
import com.sangmo.fts.process.receivable.model.RpfWaybill;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface RpfWaybillRepo extends IJpaDataViewRepo<RpfWaybill> {

    RpfWaybill findByContractId(Long contractId);

    @Query("SELECT a FROM RpfWaybill a where a.contractId = :contractId AND a.trainingId = :trainingId AND NOT EXISTS(SELECT 1 from  RpfLoan ta WHERE ta.waybillId = a.id AND ta.deleted = 0)")
    RpfWaybill findAvailableByContractId(@Param("contractId")Long contractId, @Param("trainingId") Long trainingId);
}
